<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增角色')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-role-add">
		<div class="form-group">
			<input type="hidden" th:value="${re.wareId}" name="wareId" id="wareId">
			<label class="col-sm-3 control-label is-required">仓库名称：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" th:value="${re.wareName}" name="wareName" id="roleName" required>
				<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填项，不超过30个字</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label is-required">仓库地址：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" th:value="${re.wareAddress}" name="wareAddress" id="wareAddress" required>
				<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填项，不超过300个字</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label is-required">所属区域：</label>
			<div class="col-sm-4">
				<select id="pr" class="form-control form-inline">省
					<option>请选择</option>
					<option th:each="pr:${prs}" th:value="${pr.provId}" th:selected="${pr.provId == prId.provId}" th:text="${pr.provName}"></option>
				</select >
				<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填项.</span>
			</div>
			<div class="col-sm-4">
				<select id="city" name="sysCityId" class="form-control form-inline">市
					<option th:each="city:${citys}" th:value="${city.cityId}" th:selected="${city.cityId == cityId}" th:text="${city.cityName}"></option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">负责人：</label>
			<div class="col-sm-8">
				<select id="user" name="sysChargeUserId" class="form-control form-inline">
					<option>请选择</option>
					<option th:each="u:${users}" th:value="${u.userId}" th:text="${u.userName}" th:selected="${re.sysChargeUserId == u.userId}"></option>
				</select>
				<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 只能是财务部员工.</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">备注：</label>
			<div class="col-sm-8">
				<input id="remark" name="repoDesc" class="form-control" type="text" th:value="${re.repoDesc}">
				<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 可选项.</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">状态：</label>
			<div class="col-sm-8">
				<select id="" name="repoStatus" class="form-control form-inline">
					<option value="0" th:selected="${re.repoStatus.equals('0')}">不可用</option>
					<option value="1" th:selected="${re.repoStatus.equals('1')}">可用</option>
				</select>
				<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必选项.</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label is-required">创建人：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" th:value="${user.userName}" readonly required>
				<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 不可修改</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label is-required">创建时间：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text"  th:value="${#dates.format(#dates.createNow(),'yyyy年MM月dd日')}" readonly required>
				<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 不可修改</span>
			</div>
		</div>
	</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">
	$("#pr").change(function () {
		$.get("/storage/ware/city/" + $("#pr").val(),{},function (data) {
			let options = '';
			for (let i = 0; i < data.length; i++) {
				options += '<option value="'+ data[i].cityId +'">'+ data[i].cityName +'</option>'
			}

			$("#city").html(options);
		})
	})

	/*$("#form-role-add").validate({
        rules:{
            onkeyup: false,
            roleName:{
                remote: {
                    url: ctx + "system/role/checkRoleNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "roleName" : function() {
                            return $.common.trim($("#roleName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            roleKey:{
                remote: {
                    url: ctx + "system/role/checkRoleKeyUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "roleKey" : function() {
                            return $.common.trim($("#roleKey").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            roleSort:{
                digits:true
            },
        },
        messages: {
            "roleName": {
                remote: "角色名称已经存在"
            },
            "roleKey": {
                remote: "角色权限已经存在"
            }
        },
        focusCleanup: true
    });*/

	$('input').on('ifChanged', function(obj){
		var type = $(this).val();
		var checked = obj.currentTarget.checked;
		if (type == 1) {
			if (checked) {
				$._tree.expandAll(true);
			} else {
				$._tree.expandAll(false);
			}
		} else if (type == "2") {
			if (checked) {
				$._tree.checkAllNodes(true);
			} else {
				$._tree.checkAllNodes(false);
			}
		} else if (type == "3") {
			if (checked) {
				$._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
			} else {
				$._tree.setting.check.chkboxType = { "Y": "", "N": "" };
			}
		}
	})

	function submitHandler() {
		if ($.validate.form()) {
			update();
		}
	}

	function update() {
		var wareName = $("input[name='wareName']").val();
		var wareAddress = $("input[name='wareAddress']").val();
		var sysCityId = $("select[name='sysCityId']").val();
		var sysChargeUserId = $("select[name='sysChargeUserId']").val();
		var repoStatus = $("select[name='repoStatus']").val();
		var repoDesc = $("input[name='repoDesc']").val();
		var wareId = $("#wareId").val();
		$.ajax({
			cache : true,
			type : "POST",
			url : ctx + "storage/ware/editRe",
			data : {
				"wareName": wareName,
				"wareAddress": wareAddress,
				"sysCityId": sysCityId,
				"sysChargeUserId": sysChargeUserId,
				"repoStatus": repoStatus,
				"repoDesc": repoDesc,
				"wareId": wareId
			},
			async : false,
			error : function(request) {
				$.modal.alertError("系统错误");
			},
			success : function(data) {
				$.operate.successCallback(data);
			}
		});
	}
</script>
</body>
</html>
